package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
  提高每次读写的数据量减少实际读写的次数提高读写效率
  块读写:一次读写一组字节
 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("image_dog.jpg");
        FileOutputStream fos = new FileOutputStream("image_dog_cp.jpg");

        byte[] b = new byte[1024*10];
        int len = 0;
        long start = System.currentTimeMillis();
        while ((len = fis.read(b))!=-1){
            fos.write(b,0,len);//从下标0开始，写入读取到的len个长度的字节数
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕,耗时:"+(end-start)+"ms");

        fis.close();
        fos.close();
    }
}
